/*
#include "Combat.h"
#include "PokemonLoader.h"

using namespace std;

Combat::Combat(Player& _player)
	: m_Player(_player), m_EscapeCount(0), m_CurrentPokemon(0), m_CombatEnded(false)
{

}

Combat::~Combat()
{

}

void Combat::InitEnemy()
{
	int randomPokemon;
	vector<int> pokemonPool;

	if(m_CurrentPokemon->GetLevel() > HARD_GROUP_LEVEL)
	{
		randomPokemon = rand() % HARD_GROUP_COUNT;
		pokemonPool = PokemonLoader::GetInstance()->GetGroup(HARD);
	}
	else if(m_CurrentPokemon->GetLevel() > MEDIUM_GROUP_LEVEL)
	{
		randomPokemon = rand() % MEDIUM_GROUP_COUNT;
		pokemonPool = PokemonLoader::GetInstance()->GetGroup(MEDIUM);
	}
	else
	{
		randomPokemon = rand() % EASY_GROUP_COUNT;
		pokemonPool = PokemonLoader::GetInstance()->GetGroup(EASY);
	}

	int randomLevel = rand() % 4 + (m_CurrentPokemon->GetLevel() - 2);
	m_Enemy = Pokemon(PokemonLoader::GetInstance()->GetPokemonData(pokemonPool[randomPokemon]), randomLevel);
}

void Combat::BattleFlow()
{
	m_CombatEnded = false;
	m_CurrentPokemon = m_Player.GetFirstPokemon();
	InitEnemy();

	do
	{
		int playerChoice = DisplayCombatOptions();
		system("CLS"); 

		switch(playerChoice)
		{
		case 1:
			AttackMode();
			break;
		case 2:
			SwapPokemonMode();
			break;
		case 3:
			CatchPokemonMode();
			break;
		case 4:
			EscapeMode();
			break;
		}
		if(!m_CombatEnded)
		{
			m_CurrentPokemon->EndTurnStatus();
			m_Enemy.EndTurnStatus();

			if(m_Enemy.GetCurrentHP() == 0)
			{
				m_CurrentPokemon->FightWon(m_Enemy);
				m_CombatEnded = true;
			}
		}
	}while(!m_CombatEnded);

	m_Player.InitAllPokemons();
}

bool Combat::Run()
{
	int escape = (m_CurrentPokemon->GetSpeed() * 32)/(m_Enemy.GetSpeed() / 4) + (30 * m_EscapeCount);
	m_EscapeCount++;

	if(escape > 255)
		return true;
	else
	{
		int success = rand() % 256;
		return success <= 255 ? true : false;
	}
}

bool Combat::Catch()
{
	float HpRatio = (float)m_Enemy.GetCurrentHP() / m_Enemy.GetMaxHP();
	int catchRand = rand() % 101;

	if(HpRatio > 0.7)
		return catchRand <= 10;
	else if(HpRatio > 0.5)
		return catchRand <= 25;
	else if(HpRatio > 0.3)
		return catchRand <= 40;
	else
		return catchRand <= 85;
}

void Combat::DisplayPokemons() const
{
	cout << *m_CurrentPokemon << endl << m_Enemy << endl;
}

int Combat::DisplayCombatOptions()
{
	int entry;
	bool correct = false;

	do
	{
		system("CLS");
		DisplayPokemons();

		cout << "1. Fight" << endl;
		cout << "2. Pokemon" << endl;
		cout << "3. Throw Pokeball" << endl;
		cout << "4. Run" << endl << endl;

		do
		{
			cin >> entry;
		}while(entry != 1 && entry != 2 && entry != 3 && entry != 4);

		if(entry == 2 && m_Player.GetPokemonLeftInParty() == 1)
		{
			system("CLS");
			cout << "There's no pokemon left to swap with!" << endl;
			system("pause");
		}
		else
			correct = true;
	}while(!correct);

	return entry;
}

void Combat::DisplayAttacks() const
{
	for(int i = 0; i < m_CurrentPokemon->GetAttacks().size(); i++)
	{
		cout << m_CurrentPokemon->GetAttacks()[i].GetCurrentPP() << "/" << m_CurrentPokemon->GetAttacks()[i].GetAttackData().pp << "\t" << m_CurrentPokemon->GetAttacks()[i] << endl;
	}

	cout << endl;
}
/*
void Combat::AttackMode()
{
	DisplayPokemons();

	if(m_CurrentPokemon->IsWaiting())
	{
		if(m_CurrentPokemon->GetNextAttack() != -1)
			m_CurrentPokemon->Attack(m_CurrentPokemon->GetAttackAt(m_CurrentPokemon->GetNextAttack()), m_Enemy, m_Out);
		else
		{
			cout << m_CurrentPokemon->GetName() << " must recharge!" << endl;
			m_CurrentPokemon->SetWaiting(false);
		}
	}
	else
	{
		DisplayAttacks();

		int entry;

		do
		{
			cin >> entry;
		}while(entry != 1 && entry != 2 && entry != 3 && entry != 4);
	
		system("CLS");
		DisplayPokemons();

		m_CurrentPokemon->Attack(m_CurrentPokemon->GetAttackAt(entry-1), m_Enemy);
	}
	system("pause");
	system("CLS");

	DisplayPokemons();

	if(!m_Enemy.IsAffectedBy(FAINT))
	{
		if(m_CurrentPokemon->IsWaiting())
		{
			if(m_CurrentPokemon->GetNextAttack() != -1)
				m_Enemy.Attack(m_Enemy.GetAttackAt(m_Enemy.GetNextAttack()), m_Enemy);
			else
			{
				cout << m_Enemy.GetName() << " must recharge!" << endl;
				system("pause");
				m_CurrentPokemon->SetWaiting(false);
			}
		}
		else
			m_Enemy.Attack(m_Enemy.GetAttackAt(rand() % m_Enemy.GetAttacks().size()), *m_CurrentPokemon );
		system("pause");
	}
}
void Combat::SwapPokemonMode()
{
	bool correct;
	int entry;

	do
	{
		system("CLS");

		cout << "Select your Pokemon" << endl << endl;
		m_Player.DisplayParty();

		do
		{
			cin >> entry;
		}while(entry < 1 || entry > m_Player.GetPartyCount());

		if(m_Player.GetPokemonInParty(entry-1).IsDead())
		{
			cout << "You can't select this pokemon. Its HP is 0!" << endl;
			system("pause");
		}
		else if (m_Player.GetPokemonInParty(entry-1) == *m_CurrentPokemon)
		{
			cout << m_Player.GetPokemonInParty(entry-1).GetName() << " is already out!" << endl;
			system("pause");
		}
		else
			correct = true;
	}while(!correct);

	m_CurrentPokemon = &(m_Player.GetPokemonInParty(entry-1));
}

void Combat::CatchPokemonMode()
{
	DisplayPokemons();

	if(Catch())
	{
		cout << "You caught " << m_Enemy.GetName() << endl;
		system("pause");

		system("CLS");
		DisplayPokemons();

		m_Player.AddPokemon(m_Enemy);
		m_CombatEnded = true;
	}
	else
	{
		cout << m_Enemy.GetName() << " broke free!" << endl;
		system("pause");
		system("CLS");
		DisplayPokemons();
		
		//m_Enemy.Attack(m_Enemy.GetAttackAt(rand() % m_Enemy.GetAttacks().size()), *m_CurrentPokemon );
		system("pause");
	}
}

void Combat::EscapeMode()
{
	DisplayPokemons();

	if(Run())
	{
		cout << "You succesfully escaped!" << endl;
		system("pause");
		system("CLS");

		m_CombatEnded = true;
	}
	else
	{
		cout << "You couldn't outrun " << m_Enemy.GetName() << endl;
		system("pause");
		system("CLS");
		
		//m_Enemy.Attack(m_Enemy.GetAttackAt(rand() % m_Enemy.GetAttacks().size()), *m_CurrentPokemon );
		system("pause");
	}
}
*/